<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	
<style>
.mypage{display: none;}
a.xiazai:hover{ text-decoration:none;}
</style>

<script type="text/javascript">
$(document).ready(function(){
	$('#table_content > tr:odd').css("background-color","#f5f5f5");
})
</script>


<script type="text/javascript">
//ajax 请求数据
url='';
function get_pandian(url){
	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
	dialog.content('<p>数据查询中,请稍后...<p>');
	$.get(
    	    url,
    	    {
    	    	storage_position1: ($("input[name='storage_position1']").val()=='0000')?'':$("input[name='storage_position1']").val(),
    	    	storage_position2: ($("input[name='storage_position2']").val()=='0000')?'':$("input[name='storage_position2']").val(),
    	    	storage: $("input[name='storage']").val(),
    	    	sku: $("input[name='sku']").val(),
    	    	per_page: $("select[name='per_page']").val(),
	    	    sortcondition: $("select[name='sortcondition']").val(),
	    	    order: $("select[name='order']").val(),
	    	    start_time: $("input[name='start_time']").val()
	    	 },
	    	  function(data){
	    	    	$('#table_content').empty();
	    	    	$('#table_content').html(data);
	    	    	$('#pager_links').empty();
	    	        $('.mypage').clone().appendTo('#pager_links').show();
 	    		dialog.close();
	   	   }
    	 );
}
$(function() {
	// var availableTags= [];
// 	    $( "#autocomplete" ).autocomplete({
// 	           source: availableTags
// 	    });
						$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
							$("#start").datepicker({
							});

							$("#search").click(function(){
								    url='<?php echo URL::base() ?>inventory/pandian/search';
									get_pandian(url);
								});
							
							  $(document).on('click', '.pagination a', function(e){
						      	  e.preventDefault(); 
						            url =$(this).attr('href');
						            if(url.length){
						            	get_pandian(url);
						            }
						            
						         });
							$("#down").click(function(){
								var storage_position1= $("input[name='storage_position1']").val();
								var storage_position2= $("input[name='storage_position2']").val();
								var storage= $("input[name='storage']").val();
								var sku=$("input[name='sku']").val();
					    	    var sortcondition=$("select[name='sortcondition']").val();
					    	    var order= $("select[name='order']").val();
					    	    var start_time= $("input[name='start_time']").val();
								var uri=url.split('?')[1];
								if(!uri){
									uri='sku='+sku+'&sortcondition='+sortcondition+'&order='+order+'&start_time='+start_time+'&storage_position1='+storage_position1+'&storage_position2='+storage_position2+'&storage='+storage;
								}
								window.location.href="<?php echo URL::base()?>inventory/pandian/down?"+uri;
							});

                            $("input[name='storage_position1']").keyup(function(){
                              $("input[name='storage_position2']").val($(this).val());
                            })
							  $("input[name='storage_position1']").blur(function(){
                                if($(this).val().length<4){
                                	var len=4-$(this).val().length;
                                    var str = new Array(len+1).join("0");
                                    $(this).val($(this).val()+str);
                                    $("input[name='storage_position2']").val($(this).val());
                                }

                                //添加搜索功能
                                if($(this).val()=='0000'){
									if($("input[name='storage_position2']").val()=='0000'){
										$("input[name='storage']").css({"color":""});
										$("input[name='storage']").attr("disabled", false);
									}else{
										$("input[name='storage']").css({"color":"#888"});
										$("input[name='storage']").attr("disabled", true);
									}
                                }else{
                                	$("input[name='storage']").css({"color":"#888"});
									$("input[name='storage']").attr("disabled", true);
                                }
                            });
                            $("input[name='storage_position2']").blur(function(){
                                if($(this).val().length<4){
                                	var len=4-$(this).val().length;
                                    var str = new Array(len+1).join("0");
                                    $(this).val($(this).val()+str);
                                }

                                //添加搜索功能
                                if($(this).val()=='0000'){
									if($("input[name='storage_position1']").val()=='0000'){
										$("input[name='storage']").css({"color":""});
										$("input[name='storage']").attr("disabled", false);
									}else{
										$("input[name='storage']").css({"color":"#888"});
										$("input[name='storage']").attr("disabled", true);
									}
                                }else{
                                	$("input[name='storage']").css({"color":"#888"});
									$("input[name='storage']").attr("disabled", true);
                                }
                            });
							//上传表格
                        	$(".upSuppForm").Validform({
                		        tiptype:2,
                		        postonce:true,
                    		});

                    		//添加模糊搜索
                    		$("input[name='storage']").keyup(function(){
								if($(this).val()==''){
									$("input[name='storage_position1']").attr("disabled", false);
									$("input[name='storage_position2']").attr("disabled", false);
								}else{
									if($(this).val() != '库位模糊搜索'){
										$("input[name='storage_position1']").css({"color":"#888"});
										$("input[name='storage_position2']").css({"color":"#888"});
										$("input[name='storage_position1']").attr("disabled", true);
										$("input[name='storage_position2']").attr("disabled", true);
									}else{
										$("input[name='storage_position1']").attr("disabled", false);
										$("input[name='storage_position2']").attr("disabled", false);
									}
								}
                        	});
                        	$("#reset_").click(function(){
                        		$("input[name='storage_position1']").attr("disabled", false);
								$("input[name='storage_position2']").attr("disabled", false);
								$("input[name='storage']").attr("disabled", false);
                           	});
})
		</script>

			<form class="form-horizontal" >
			<div class="control-group">
    	      		<label class="control-label w-label">库位:</label>
					<div class="controls">
						<div class="input-append">
						   <input class="span2" style="width:125px;"  type="text" name="storage_position1" onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')" onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')" >
						   <span class="add-on">0000</span>
                          </div>
                           &nbsp;&nbsp;~&nbsp;&nbsp;
					   <div class="input-append">
						  <input style="width:125px;" class="span2" style="width:164px;" type="text" name="storage_position2" onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')" onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')" >
						  <span class="add-on">0000</span>
                       </div> 
					</div>
			</div>
		
		
				<!-- 添加模糊搜索 -->
				<div class="control-group">
					<label class="control-label w-label">搜索:</label>
					<div class="controls">
						<input type="text" placeholder="库位模糊搜索" name="storage">
					</div>
				</div>
		
		
    	      	<div class="control-group">
    	      		<label class="control-label w-label">SKU:</label>
					<div class="controls">
						<input type="text" name='sku' value="">

					</div>
				</div>
					<div class="control-group">
    	      		<label class="control-label w-label">自定义页数:</label>
					<div class="controls">
						<select  name='per_page'>
							<option value="">选择（默认15）</option>
							<option value='30'>30</option>
							<option value='40'>40</option>
							<option value='50'>50</option>
						</select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label">排序条件:</label>
					<div class="controls">
						<select  name='sortcondition'>
							<option value="4">选择（默认储位）</option>
							<option value='1'>SKU</option>
							<option value='2'>供应商</option>
							<option value='3'>期初实际库存</option>
							<option value='4'>储位</option>
						</select>
					</div>
				</div>
					<div class="control-group">
					<label class="control-label w-label">排序方式:</label>
					<div class="controls">
						<select name='order'>
							<option value='1'>升序</option>
							<option value='2'>降序</option>
						</select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label" for="inputPassword">盘点截至日期:</label>
					<div class="controls">
						<input type="text" name='start_time' class=" datepicker" id="start" value="<?php echo date('Y-m-d')?>"
						readonly="readonly" >&nbsp;&nbsp;<label style="font-size: 17px">23:59:59</label>
                        <button class="btn btn-info" id="search">查询</button>
                        <input style="margin-left:10px;" type="reset" value="重 置" class="btn btn-inverse" id="reset_">
					</div>
					
				<div>
			</form>

<table class="table table-hover" style="border-collapse: collapse; margin-top: 15px;">
<thead>
<tr>
  <th>SKU</th>
  <th>中文名称</th>
  <th>储位</th>
  <th>库存量</th>
  <th>延迟量</th>
  <th>实际库存量</th>
  <th>借料备注量</th>
</tr>
</thead>
 <tbody id='table_content'>
</tbody>
</table>
<div class="alert alert-success">
    <p>注：借料显示出来，但是借料与所展示库存数量没有关联,即借料并没有在库存量扣除</p>
    <p>延迟量：代表本小时内还未来得及导入新系统的出库单</p>
</div>
<div id="pager_links"></div>
<div class="btn btn-success" id='down'><a class="xiazai" style="color:#FFF;" >下载</a></div>
<h2>库存盘点批量上传：</h2>
  <form class="upSuppForm" method='post' action='<?php echo URL::site() ?>inventory/pandian/upload_pandian' enctype="multipart/form-data">
  <table class="table table-striped">
     <tr>
       <td class="need"></td>
                    <td>批量上传</td>
                    <td> <input type='file'   style="line-height: 0px;" name='xls' class="inputxt" datatype="/.+\.xls/"  nullmsg="请选择上传文件"  errormsg="文件格式只能为xls"/></td>
                    <td><div class="Validform_checktip"></div></td>
      </tr>
      <tr>
	       <td class="need"></td>
	       <td></td>
	       <td colspan="2">
	       
	       </td>
      </tr>
     </table>
      <input type='submit' value='上传' class='btn btn-success'  id="upload"/>
  </form>
  

